package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ASM_DBlistDS {
	
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;

	public ASM_DBlistDS (Context context)
	{
		this.context = context;
		dbHelper = new ASM_DB(context);
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_DBlist det) {
		
		int count =0;
		
		if(dB == null)
		{
			open();
		}
		else if(!dB.isOpen())
		{
			open();
		}

		
		
		ContentValues values = new ContentValues();
		values.put(ASM_DB.ASM_DBNAME, det.getASM_DBNAME());
		count = (int) dB.insert(ASM_DB.ASM_DBLIST, null, values);
		dB.close();
		return count;
		
	}
	
	
	//select data
	public ArrayList<String> getAllASM_DBlist() 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		ArrayList<String> Details = new ArrayList<String>();
	
		String selectQuery = "select "+ASM_DB.ASM_DBNAME+" from serverdb";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
			int lkk = cursor.getCount();
			//for(int i = 0;i<cursor.getCount();i++)
			//{
			Log.v("ASMDB LISTDS", Integer.toString(lkk));
			Details.add(cursor.getString(0));
			//}
			
		}
		
		return Details;
	}

}
